import inspect

def test__str_to_bool():
    print()
    print(f'running [{inspect.currentframe().f_code.co_name}] ...')
    from kinyx.type_util import str_to_bool

    print('--------------------------------------------------------------------')
    print('code                               expect           result')
    print()
    print("str_to_bool(None)                  None            ", str_to_bool(None))
    print("str_to_bool('t')                   True            ", str_to_bool('t'))
    print("str_to_bool('f')                   False           ", str_to_bool('f'))

    flag = False

    # 参数校验未通过
    try:
        print(str_to_bool(0))
        flag = True
    except:
        pass
    if flag: raise ValueError()
    print("str_to_bool(0)                     Error           Error")

    # 不支持的转换
    try:
        print(str_to_bool('x'))
        flag = True
    except:
        pass
    if flag: raise ValueError()
    print("str_to_bool('x')                   Error           Error")
    print('--------------------------------------------------------------------')

def test__str_to_int():
    print()
    print(f'running [{inspect.currentframe().f_code.co_name}] ...')
    from kinyx.type_util import str_to_int

    print('--------------------------------------------------------------------')
    print('code                              expect           result')
    print()
    print("str_to_int(None)                  None            ", str_to_int(None))
    print("str_to_int('0')                   0               ", str_to_int('0'))
    print("str_to_int('1')                   1               ", str_to_int('1'))

    flag = False

    # 参数校验未通过
    try:
        print(str_to_int(0))
        flag = True
    except:
        pass
    if flag: raise ValueError()
    print("str_to_int(0)                     Error           Error")

    # 不支持的转换
    try:
        print(str_to_int('x'))
        flag = True
    except:
        pass
    if flag: raise ValueError()
    try:
        print(str_to_int('3.3'))
        flag = True
    except:
        pass
    if flag: raise ValueError()
    print("str_to_int('3.3')                 Error           Error")
    print('--------------------------------------------------------------------')


def test__str_to_float():
    print()
    print(f'running [{inspect.currentframe().f_code.co_name}] ...')
    from kinyx.type_util import str_to_float

    print('--------------------------------------------------------------------')
    print('code                                expect           result')
    print()
    print("str_to_float(None)                  None            ", str_to_float(None))
    print("str_to_float('0')                   0.0             ", str_to_float('0'))
    print("str_to_float('1')                   1.0             ", str_to_float('1'))
    print("str_to_float('3.3')                 3.3             ", str_to_float('3.3'))

    flag = False

    # 参数校验未通过
    try:
        print(str_to_float(0))
        flag = True
    except:
        pass
    if flag: raise ValueError()
    print("str_to_float(0)                     Error           Error")

    # 不支持的转换
    try:
        print(str_to_float('x'))
        flag = True
    except:
        pass
    if flag: raise ValueError()
    print("str_to_float('x')                   Error           Error")
    print('--------------------------------------------------------------------')


test__str_to_bool()
test__str_to_int()
test__str_to_float()

def test__xxx_to_str():
    print()
    print(f'running [{inspect.currentframe().f_code.co_name}] ...')
    
    from kinyx.type_util import bool_to_str
    print('bool_to_str(True) ->', bool_to_str(True))
    
    from kinyx.type_util import int_to_str
    print('int_to_str(1) ->', int_to_str(1))
    
    from kinyx.type_util import float_to_str
    print('float_to_str(3.3) ->', float_to_str(3.3))

test__xxx_to_str()